package com.eve.controller;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;

import com.eve.DAObjects.ClientDAO;
import com.eve.DAObjects.GenericList;
import com.eve.DAObjects.GenericListDAO;

public class BaseController {
	ApplicationContext context;
	GenericListDAO genericDao;
	ClientDAO clientDao;
	public BaseController(){
		ApplicationContext context1 = new ClassPathXmlApplicationContext("classpath:com/eve/DAObjects/GenListDAO.xml");
		genericDao = (GenericListDAO) context1.getBean("GenericListDAO");
		ApplicationContext content2 = new ClassPathXmlApplicationContext("classpath:com/eve/DAObjects/ClientDAOModule.xml");
		clientDao = (ClientDAO) content2.getBean("ClientDAO");
	}
	@ModelAttribute("needCategory")
	public List<GenericList> populateNeedList() throws IOException, ClassNotFoundException, SQLException {
		List<GenericList> needCategory = genericDao.getOptionList("need");
		return needCategory;
	}
	@ModelAttribute("cityList")
	public List<GenericList> poplateCityList() throws FileNotFoundException, ClassNotFoundException, SQLException, IOException{
		List<GenericList> cityList = genericDao.getOptionList("city");
		return cityList;
	}

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
}
